package cn.dzhang.rcp.hyperbola.adapters;

import org.eclipse.jface.viewers.ITableColorProvider;
import org.eclipse.jface.viewers.ITableFontProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;

import cn.dzhang.rcp.hyperbola.common.UIUtils;

public class TableViewerLabelProvider extends LabelProvider implements
		ITableColorProvider, ITableLabelProvider, ITableFontProvider {

	@Override
	public Color getForeground(Object element, int columnIndex) {
		IWorkbenchAdapter4 adapter = UIUtils.getAdapter4(element);
		return adapter == null ? null : adapter.getForeground(element,
				columnIndex);
	}

	@Override
	public Color getBackground(Object element, int columnIndex) {
		IWorkbenchAdapter4 adapter = UIUtils.getAdapter4(element);
		return adapter == null ? null : adapter.getBackground(element,
				columnIndex);
	}

	@Override
	public Image getColumnImage(Object element, int columnIndex) {
		IWorkbenchAdapter4 adapter = UIUtils.getAdapter4(element);
		return adapter == null ? null : adapter.getColumnImage(element,
				columnIndex);
	}

	@Override
	public String getColumnText(Object element, int columnIndex) {
		IWorkbenchAdapter4 adapter = UIUtils.getAdapter4(element);
		return adapter == null ? element.toString() : adapter.getColumnText(
				element, columnIndex);
	}

	@Override
	public Font getFont(Object element, int columnIndex) {
		IWorkbenchAdapter4 adapter = UIUtils.getAdapter4(element);
		return adapter == null ? null : adapter.getFont(element, columnIndex);
	}

}
